package org.example.myleet.rosalind.mprt;

import org.example.myleet.rosalind.utils.FastaReader;
import org.example.myleet.rosalind.utils.FastaSequence;

import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Solution {

    private static final Pattern GLYCOSYLATION_MOTIF = Pattern.compile("N[^P][ST][^P]");

    public void findAllGlycosylationMotifs(List<FastaSequence> sequences) {
        for (FastaSequence sequence : sequences) {
            Matcher matcher = GLYCOSYLATION_MOTIF.matcher(sequence.getSequence());
            StringBuilder sb = new StringBuilder();
            int p = 0;
            while (matcher.find(p)) {
                p = matcher.start();
                sb.append(p + 1).append(' ');
                ++p;
            }
            if (sb.length() > 0) {
                System.out.println(sequence.getTag());
                sb.deleteCharAt(sb.length() - 1);
                System.out.println(sb);
            }
        }
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        String path = solution.getClass().getResource("").getPath() + "sequence.txt";
        solution.findAllGlycosylationMotifs(FastaReader.parseFastaFromFile(path));
    }
}
